java.lang.ObjectMoney
public class Money
An amount of money in Canadian currency; i.e., dollars and cents.
| Constructor Summary | |
|---|---|
Money(int cents)
Constructs a Money object whose value is equal to the specified quantity of cents, which can be positive or negative, and < -99 or > 99. |
|
Money(int dollars,
int cents)
Constructs a Money object whose value is equal to the specified quantity of dollars and cents, both of which can be positive or negative. |
|
| Method Summary | |
|---|---|
Money |
addMonies(int number,
int cents,
java.lang.Object obj)
A method to use for learning about exceptions. |
int |
compareTo(java.lang.Object obj)
Compares this Money object with the specified Money object for order. |
Money |
dividedBy(int anAmount)
Returns the result of dividing this Money object an integer amount. |
boolean |
equals(java.lang.Object obj)
Compares this object against the specified object. |
boolean |
isEqualTo(Money anAmount)
Compares this Money object against the specified Money object. |
Money |
minus(Money anAmount)
Returns the difference of this Money object and the specified amount of money. |
Money |
multipliedBy(int anAmount)
Returns the result of multiplying this Money object an integer amount. |
Money |
plus(Money anAmount)
Returns the sum of this Money object and the specified amount of money. |
java.lang.String |
toString()
Returns a String representation of this Money object in the form: "$ddd.cc" or "-$ddd.cc", where ddd is the dollars part and cc is the cents part. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Money(int cents)
cents - A quantity of cents.Money(int, int)
public Money(int dollars,
int cents)
dollars - A quantity of dollars.cents - A quantity of cents.
java.lang.IllegalArgumentException - if cents outside valid rangeMoney(int)| Method Detail |
|---|
public Money addMonies(int number,
int cents,
java.lang.Object obj)
throws java.lang.Exception
number - A number between 1 and 10cents - The number of cents (between 0 and 99)obj - An object
an - IllegalArgumentException if number is not between 1 and 10.
an - IllegalArgumentException if cents is not between 0 and 99.
a - NullPointerException if obj is null.
a - ClassCastException if obj is not a Money object.
java.lang.Exceptionpublic int compareTo(java.lang.Object obj)
compareTo in interface java.lang.Comparablepublic Money dividedBy(int anAmount)
anAmount - the integer that is to be divided into this object.
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - the object that is compared to this object.
public boolean isEqualTo(Money anAmount)
anAmount - the Money object that is to be compared to this object.
public Money minus(Money anAmount)
anAmount - the Money object that is to be subtracted from this object.
public Money multipliedBy(int anAmount)
anAmount - the integer that is to be multiplied by this object.
public Money plus(Money anAmount)
anAmount - the Money object that is to be added to this object.
public java.lang.String toString()
toString in class java.lang.Object